var multer = require("multer");

//设置文件存储位置和文件命名
var storage = multer.diskStorage({
  //   destination: function (req, file, cb) {
  //     //目录不会自动创建
  //     cb(null, "uploads/");
  //   },
  destination: "uploads/", //目录无则自动创建
  filename: function (req, file, cb) {
    // console.log(file, 999);
    let filename = file.originalname; //wzj.jpg
    let arr = filename.split("."); //['wzj','jpg']
    // cb(null, file.fieldname + "-" + Date.now());
    cb(null, arr[0] + "-" + Date.now() + "." + arr[1]);
  },
});

var upload = multer({ storage });

module.exports = upload;
